/**
 * 文件下载
 */
function download(){
		$.ajax({
			type:'POST',
			url:'expose/resource/getResourceScore?id='+$('#rfId').val(),
			dataType:'json',
			success:function(data){
			if(data && data.success){
				var url = "expose/resource/downloadResource?id="+$('#rfId').val();
				showAlertDiv(data.message+'<a href="'+url+'" style=\"color:red;\" >立即下载</a>');
				}else{
					if(data.code == 104){
							showAlertDiv(data.message+',<a href=\"\" style=\"color:red;\">立即充值</a>');
							return;
					}else if(data.code == 102){
							showDiv(data.message);
					}else{
							showAlertDiv(data.message);
					}
			}
		}
	});
}
		
/**
 * 资源收藏
 */
function collection(){
		$.ajax({
			type:'POST',
			url:'expose/resource/collectionResource?id='+$('#rfId').val(),
			dataType:'json',
			success:function(data){
						if(data && data.success){
								showAlertDiv(data.message);
						}else if(data.code == 102){
								showDiv(data.message);
						}else{
								showAlertDiv(data.message);
						}
			}
		});
	}
					
/**
 * 资源评论
 **/
function comment(){
		$.ajax({
			type:'POST',
			url:'expose/rescomment/commentResource?resourceId='+$('#rfId').val(),
			dataType:'json',
			data:{"commentContent":"111"},
			success:function(data){
					if(data && data.success){
							showAlertDiv(data.message);
					}else if(data.code == 102){
							showDiv(data.message);
					}else{
							showAlertDiv(data.message);
					}
				}
		});
	}

/**
 * 问题收藏，关注
 **/
function operation(type){
		$.ajax({
		type:'POST',
		url:'expose/question/questionOperation',
		data:{'id':$('#questionId').val(),'type':type},
		dataType:'json',
		 success:function(data){
					if(data && data.success){
						showAlertDiv(data.message);
						switch(type){
							 case 1:
								$("#gz").html(data.object.questionAbout);
								break;
							case 2:
								$("#sc").html(data.object.questionCollection);
							break;
						}
					}else if(data.code==102){
						showDiv(data.message);
					}else{
						showAlertDiv(data.message);
					}
				}
	});
}
	
/**
 * 设置文章字体大小
 * @param size
 */
function doZoom(size) {
	document.getElementById('zoom').style.fontSize = size+ 'px';
}

/**js收藏*/
function addfavorite() { 
	 var url = window.location.href;
	  var title = document.title;
	    try {
	        window.external.addFavorite(url, title);
	    }
	    catch (e) {
	        try {
	            window.sidebar.addPanel(title, url, "");
	        }
	        catch (e) {
	            alert("抱歉，您所使用的浏览器无法完成此操作，请使用Ctrl+D进行添加");
	        }
	    }
} 

/**
 * 注册邮箱激活
 */
function activate(){
	$.ajax({
		type:'POST',
		url:'registerActivateStatus',
		data:{'username':$('#username').val()},
		dataType:'json',
		 success:function(data){
					if(data && data.success){
						showAlertDiv(data.message);
					}else{
						showAlertDiv(data.message);
					}
				}
	});
}


/**
 *发送修改密码地址到邮箱
 */
function updatePwdSendEmail(){
	var email = $('#email').val();
	if(email == ''){
		$('.errorMsg').html('邮箱不能为空!');
		return;
	}
	$.ajax({
		type:'POST',
		url:'updatePwdSendEmail',
		data:{'email':$('#email').val()},
		dataType:'json',
		 success:function(data){
					if(data && data.success){
						showAlertDiv(data.message);
					}else{
						showAlertDiv(data.message);
					}
				}
	});
}


/**
 * 修改密码
 */
function updatePassword(){
	var pwd  = $('#password').val();
	var confrmPassword  = $('#confrmPassword').val();
	if(pwd == '' || pwd.length<6 || pwd.length>12 || confrmPassword == ''){
		showAlertDiv("密码或确认密码不能为空，且长度必须在6~12位!");
	}else if(!/^\w{6,12}$/.test(pwd)){
		showAlertDiv("密码必须由字母,数字或者下划线组成!");
	}else if(pwd !=confrmPassword ){
		showAlertDiv("两次输入的密码不一致!");
	}else{
		$.ajax({
			type:'POST',
			url:'updatePwdByEmail',
			data:{'id':$('#id').val(),'password':$('#password').val()},
			dataType:'json',
			 success:function(data){
						if(data && data.success){
							showAlertDiv(data.message);
						}else{
							showAlertDiv(data.message);
						}
					}
		});
	}
}
//logo图片轮播
function listLogo(){
	$.ajax({
		type:'POST',
		url:'listLogos',
		dataType:'json',
		success:function(data){
			if(data){
				for(var i=0;i<data.length;i++){
						var logoDiv = "<div class=\"innerwraper\"><img src=\"homeLogo?id="+data[i].id +"\" alt=\""+data[i].imgName +"\" /></div> ";
						$('#logos').append(logoDiv);
				}
			}
		}
	});
}

$(function(){
	listLogo();
	//鼠标滚动监听事件
	var maxScrollTop = 1000;
	var $top = $("#top");
	// 向下滚动到据顶部超过1000px时，回到顶部
/*	$(window).scroll( maxScrollTop, function(event){
	    var $me = $(this);
	    if( $me.scrollTop() > event.data ){
	    	$top.style.position = "fixed";
	    	$top.style.top = "0";
	    	$top.style.margin = "0";
//	        $me.scrollTop( 0 );
	    	 if (t > mt) {
                 mydiv.style.position = "fixed";
                 mydiv.style.margin = "0";
                 mydiv.style.top = "0";
             }else {
                 mydiv.style.margin = "20px 0";
                 mydiv.style.position = "static";
             }
	    }
	} );*/
});
